<template>
  <div class="testTaskDetailBaseInfo">
    <h4 class="withVerticleLineT4 title14">
      <!-- <a v-if="infoData.isEqualUpgrade === true">[{{ $t('equalUpgrade') }}]</a> -->
      {{ $t('testTaskInfo') }}</h4>
    <div class="baseInfoItems">
      <full-parent-dom-with-dask :loading="loadingInfoData"></full-parent-dom-with-dask>
      <!-- 任务名称 -->
      <a-row class="baseInfoItem">
        <a-col :md="8" :sm="14">{{ '任务名称' }}</a-col>
        <a-col
          :md="16"
          :sm="10"
          class="result"
        ><table-ellipsis :tableEllipsisIsTurnLine="false" :text="infoData.name"></table-ellipsis
        ></a-col>
      </a-row>
      <!-- 升级类型 -->
      <a-row class="baseInfoItem">
        <a-col :md="8" :sm="14">{{ $t('upgradeType') }}</a-col>
        <a-col
          :md="16"
          :sm="10"
          class="result"
        ><table-ellipsis :tableEllipsisIsTurnLine="false" :text="testTaskTypeObj[infoData.type]"></table-ellipsis
        ></a-col>
      </a-row>
      <!-- 是否强制升级 -->
      <a-row class="baseInfoItem" v-if="[9, 10].includes(infoData.type)">
        <a-col :md="8" :sm="14">{{ $t('isQzsj') }}</a-col>
        <a-col :md="16" :sm="10" class="result">
          <table-ellipsis
            :tableEllipsisIsTurnLine="false"
            :text="forceUpgradeTypeObj[infoData.forceUpgrade] || '-'"
          ></table-ellipsis>
        </a-col>
      </a-row>
      <!-- 是否静默升级 -->
      <a-row class="baseInfoItem" v-if="infoData.type === 8">
        <a-col :md="8" :sm="14">{{ $t('sfjmsj') }}</a-col>
        <a-col :md="16" :sm="10" class="result">
          <table-ellipsis
            :tableEllipsisIsTurnLine="false"
            :text="slienceUpgradeTypeObj[infoData.silenceUpgrade] || '-'"
          ></table-ellipsis>
        </a-col>
      </a-row>
      <!-- 循环升级策略 -->
      <a-row class="baseInfoItem" v-if="infoData.type === 10">
        <a-col :md="8" :sm="14">{{ $t('circularUpgradeStrategy') }}</a-col>
        <a-col :md="16" :sm="10" class="result">
          <a
            @click="lookupSjcl(infoData.circleStrategyId, 1)"
          ><table-ellipsis
            :tableEllipsisIsTurnLine="false"
            :text="infoData.circleStrategyName || '-'"
          ></table-ellipsis
          ></a>
        </a-col>
      </a-row>
      <!-- 循环升级任务 -->
      <a-row class="baseInfoItem" v-if="infoData.type === 10">
        <a-col :md="8" :sm="14">{{ $t('circularUpgradeTask') }}</a-col>
        <a-col
          :md="16"
          :sm="10"
          class="result"
        ><table-ellipsis :tableEllipsisIsTurnLine="false" :text="infoData.circleTaskName || '-'"></table-ellipsis
        ></a-col>
      </a-row>
      <!-- 任务状态 -->
      <a-row class="baseInfoItem">
        <a-col :md="8" :sm="14">{{ $t('campaignStatus') }}</a-col>
        <a-col
          :md="16"
          :sm="10"
          class="result"
        ><table-ellipsis
          :tableEllipsisIsTurnLine="false"
          :text="taskUpdateDictCodeObj[infoData.status] || '-'"
        ></table-ellipsis
        ></a-col>
      </a-row>
      <!-- 批次号 -->
      <!-- <a-row class="baseInfoItem">
        <a-col :md="8" :sm="14">批次号</a-col>
        <a-col
          :md="16"
          :sm="10"
          class="result"
        ><table-ellipsis :tableEllipsisIsTurnLine="false" :text="infoData.batchNo || '-'"></table-ellipsis
        ></a-col>
      </a-row> -->
      <!-- 唤醒通道 -->
      <a-row v-if="infoData.type=='8'" class="baseInfoItem">
        <a-col :md="8" :sm="14">{{ $t('hxtd') }}</a-col>
        <a-col
          :md="16"
          :sm="10"
          class="result"
        ><table-ellipsis
          :tableEllipsisIsTurnLine="false"
          :text="factoryChannelObj[infoData.factoryChannel] || '-'"
        ></table-ellipsis
        ></a-col>
      </a-row>
      <!-- 生效时间 -->
      <a-row class="baseInfoItem">
        <a-col :md="8" :sm="14">{{ $t('taskEffectiveTime') }}</a-col>
        <a-col
          :md="16"
          :sm="10"
          class="result"
        ><table-ellipsis
          v-if="infoData.type==8"
          :tableEllipsisIsTurnLine="false"
          :text="$commonFun.getDateMinuteStr(infoData.startTime) || '-'"
        ></table-ellipsis
        >
        <div v-else>永久</div></a-col>
      </a-row>
      <!-- 失效时间 -->
      <a-row class="baseInfoItem" v-if="infoData.type==8">
        <a-col :md="8" :sm="14">{{ $t('taskFailureTime') }}</a-col>
        <a-col :md="16" :sm="10" class="result">{{ $commonFun.getDateMinuteStr(infoData.endTime) || '-' }}</a-col>
      </a-row>
      <!-- 是否自由烧写 -->
      <!-- <a-row class="baseInfoItem" v-if="[9, 10].includes(infoData.type)">
        <a-col :md="8" :sm="14">是否自由烧写</a-col>
        <a-col
          :md="16"
          :sm="10"
          class="result"
        >
          <table-ellipsis
            :tableEllipsisIsTurnLine="false"
            :text="freeBurningTypeObj[infoData.freeBurning] || '-'"></table-ellipsis>
        </a-col>
      </a-row> -->
      <!-- 烧写方式 -->
      <a-row class="baseInfoItem" v-if="versionType=='develop'">
        <a-col :md="8" :sm="14">烧写方式</a-col>
        <a-col
          :md="16"
          :sm="10"
          class="result"
        >
          <table-ellipsis
            :tableEllipsisIsTurnLine="false"
            :text="infoData.freeBurning?'自由烧写':infoData.isEqualUpgrade?'平刷':'正常OTA'"></table-ellipsis>
        </a-col>
      </a-row>
    </div>
    <!-- 查看策略详情 -->
    <show-strategy-info ref="showStrategy" :updata-strategy-id="strategyId" :strategy-type="strategyType">
    </show-strategy-info>
  </div>
</template>
<script>
import FullParentDomWithDask from '@/components/LoadDataSpin/FullParentDomWithDask.vue'
import TableEllipsis from '@/components/Ellipsis/TableEllipsis'
import taskApi from '@/api/modules/task'
import ShowStrategyInfo from '@/views/components/ShowConditionUpdateStrategy'
import { mapGetters } from 'vuex'
const initInfoData = {
  name: '',
  startTime: '',
  endTime: '',
  status: '',
  type: -1,
  circleStrategyId: '',
  circleStrategyName: '',
  circleTaskName: '',
  forceUpgrade: '',
  silenceUpgrade: '',
  factoryChannel: '',
  batchNo: '',
  freeBurning: ''
}
export default {
  components: {
    FullParentDomWithDask,
    TableEllipsis,
    ShowStrategyInfo
  },
  props: {
    versionType: {
      type: String,
      default: ''
    },
    taskId: {
      type: String,
      default: ''
    }
  },
  computed: {
    ...mapGetters(['drawerOpenTime']),
    taskUpdateDictCodeObj () {
      return this.$store.getters.getDictCodeObj('taskUpdateDictCode')
    },
    forceUpgradeTypeObj () {
      return this.$store.getters.getTaskDictCodeObj('forceUpgradeType')
    },
    slienceUpgradeTypeObj () {
      return this.$store.getters.getTaskDictCodeObj('slienceUpgradeType')
    },
    testTaskTypeObj () {
      return this.$store.getters.getTaskDictCodeObj('testTaskType')
    },
    factoryChannelObj () {
      return this.$store.getters.getDictCodeObj('factoryChannelDictCode')
    },
    freeBurningTypeObj () {
      return this.$store.getters.getTaskDictCodeObj('freeBurningType')
    }
  },
  data () {
    return {
      loadingInfoData: false,
      infoData: { ...initInfoData },
      strategyId: '',
      strategyType: 'Fota'
    }
  },
  watch: {
    taskId: {
      handler (val) {
        console.log(val, 'taskId2')
        this.getData()
      }
    },
    drawerOpenTime: {
      handler () {
        console.log(this.taskId, 'taskId2=1')
        this.getData()
      },
      immediate: true
    }
  },
  created () {
    this.getPageDictData()
  },
  methods: {
    deliverEndTime () {
      this.$emit('deliverEndTime', this.infoData.endTime)
    },
    // 获取当前测试任务基本信息
    getData () {
      this.infoData = { ...initInfoData }
      if (!this.taskId || this.loadingInfoData) {
        return
      }
      this.loadingInfoData = true
      taskApi
        .getTaskInfor({ id: this.taskId })
        .then((res) => {
          if (!res.data) {
            return
          }
          const { data } = res
          this.infoData = {
            name: data.name,
            startTime: data.startTime,
            endTime: data.endTime,
            status: data.status,
            type: data.type,
            circleStrategyId: data.circleStrategyId,
            circleStrategyName: data.circleStrategyName,
            circleTaskName: data.circleTaskName,
            forceUpgrade: data.forceUpgrade,
            silenceUpgrade: data.silenceUpgrade,
            factoryChannel: data.factoryChannel,
            batchNo: data.batchNo,
            isEqualUpgrade: data.isEqualUpgrade,
            freeBurning: data.freeBurning
          }
          this.deliverEndTime()
        })
        .finally(() => {
          this.loadingInfoData = false
        })
    },
    // 查看升级策略
    lookupSjcl (strategyId, type) {
      this.strategyId = strategyId
      this.strategyType = type === 2 ? 'Sota' : 'Fota'
      if (this.strategyId) {
        this.$refs.showStrategy.visible = true
      }
    },
    getPageDictData () {
      ;['getTaskUpdateDictCodeData', 'getFactoryChannelDictCodeData'].forEach((method) => {
        this.$store.dispatch(method)
      })
    }
  }
}
</script>
<style lang="less" scoped>
.testTaskDetailBaseInfo {
  padding-top: 24px;
  .baseInfoItems {
    position: relative;
    border-bottom: 1px solid @borderColor;
    padding-bottom: 20px;
  }
  .baseInfoItem {
    margin-top: 15px;
    .result {
      text-align: right;
    }
  }
}
</style>
